{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD8CAYAAAB+UHOxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3XmYFNXZ9/HvDQMiggoBDbIETEBZVMQRUeISFzZFlKiAiho1GBUDLhiX+CTq+8TdiImiIEaNCyKg4oKyuGAeFR1QECQIkSiDqLiCGwhzv3+cmumeYWB6Znqmuqd/n+vqi6pT1V13zzDnrjrn1Clzd0REJPfUizsAERGJhxKAiEiOUgIQEclRSgAiIjlKCUBEJEcpAYiI5CglABGRHKUEICKSo5QARERyVF7cAWxLixYtvH379nGHISKSVebPn/+Zu7esaL+MTgDt27enoKAg7jBERLKKmX2Qyn5qAhIRyVFKACIiOUoJQEQkRykBiIjkKCUAEZEcpQQgIpKjlABERKrDbMtXNd11FzzwQBpiq0BG3wcgIpJrHnsMzjsP3OHTT+GSS2ruWLoCEBHJEC+8AKeeGip/CMlg48aaO54SgIhIBliwAAYNSlT4e+wBzzwDDRvW3DGVAEREYrZiBfTvD998E9Zbt4aZM6FFi5o9rhKAiEiM1qyBPn1Cez9As2bw/PPQrl3NH7vCBGBmbc3sRTNbamZLzGxUVL6Pmb1mZu+Y2VNmtmPSey43sxVmtszM+iaV94vKVpjZZTXzlUREssNXX0G/frByZVjffnt4+mno2rV2jp/KFcAm4GJ37wz0As43sy7APcBl7r4X8DgwBiDaNhToCvQD7jSz+mZWH7gD6A90AYZF+4qI5Jzvvw9t/osWhfX69UOn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RHarpe6+61xx1OWu1/u7m3cvT3h5/eCu2fU2au7fwysMrM9oqIjgHdjDKmsD4FeZtY4+n0fQQZ1UpcxHTg9Wj4deDLGWMplZv2APwDHuvt3ccdTlru/4+67uHv76O+mEOgR/T/NWHUuAUQdRSOB5wl/cJPdfUm8UW2hNzCccGb9dvQaEHdQWegC4CEzWwR0B/4SczwloiuTKcAC4B3C31rsd4qa2SPAa8AeZlZoZmcB1wNHmdlywgiW6zMwxr8DTYFZ0d/LXRkYY9bRncAiIjmqzl0BiIhIapQARERylBKAiEiOUgIQEclRSgAiIjlKCUBEJEcpAYiI5CglABGRHPX/ATZ1Nw0OgOUhAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 日期数据 一共15天\n",
    "date = np.linspace(1,15,15)\n",
    "# 收盘价格\n",
    "endPrice = np.array([2511.90,2538.26,2510.68,2591.66,2732.98,2701.69,2701.29,2678.67,2726.50,2681.50,2739.17,2715.07,2823.58,2864.90,2919.08])\n",
    "# 开盘价格\n",
    "beginPrice = np.array([2438.71,2500.88,2534.95,2512.52,2594.04,2743.26,2697.47,2695.24,2678.23,2722.13,2674.93,2744.13,2717.46,2832.73,2877.40])\n",
    "# print(date)\n",
    "plt.figure()\n",
    "# 用for-loop绘制15天数据\n",
    "for i in range(0,15):\n",
    "    # 柱状图\n",
    "    # 日期数据\n",
    "    dateOne = np.zeros([2])\n",
    "    dateOne[0] = i\n",
    "    dateOne[1] = i\n",
    "    # 价格数据\n",
    "    priceOne = np.zeros([2])\n",
    "    priceOne[0] = beginPrice[i]\n",
    "    priceOne[1] = endPrice[i]\n",
    "    # 若当天收盘价大于开盘价则股票上涨，用红色标注，不然为股票下跌，用绿色标注\n",
    "    if endPrice[i] > beginPrice[i]:\n",
    "        plt.plot(dateOne,priceOne,'r',lw=5)\n",
    "    else:\n",
    "        plt.plot(dateOne,priceOne,'g',lw=5)\n",
    "# 绘制相应的柱状图\n",
    "# plt.show()\n",
    "# 实现人工神经网络（ANN）\n",
    "# 为了便于计算，将日期归一化\n",
    "dateNormal = np.zeros([15,1])\n",
    "priceNormal = np.zeros([15,1])\n",
    "# i从0到14\n",
    "for i in range(0,15):\n",
    "    dateNormal[i,0] = i/14.0\n",
    "    priceNormal[i,0] = endPrice[i]/3000.0\n",
    "# 输入层：N行1列 x为日期，y为价格\n",
    "x = tf.placeholder(tf.float32,[None,1])\n",
    "y = tf.placeholder(tf.float32,[None,1])\n",
    "# 隐藏层\n",
    "# w1为1*10d的随机变量矩阵，矩阵中的值介于0,1之间\n",
    "w1 = tf.Variable(tf.random_uniform([1,10],0,1))\n",
    "b1 = tf.Variable(tf.zeros([1,10]))\n",
    "wb1 = tf.matmul(x,w1)+b1\n",
    "# 激活函数\n",
    "layer1 = tf.nn.relu(wb1)\n",
    "# 输出层\n",
    "w2 = tf.Variable(tf.random_uniform([10,1],0,1))\n",
    "b2 = tf.Variable(tf.zeros([15,1]))\n",
    "wb2 = tf.matmul(layer1,w2)+b2\n",
    "layer2 = tf.nn.relu(wb2)\n",
    "# 损失函数 (y - predict)^2 即标准差\n",
    "loss = tf.reduce_mean(tf.square(y - layer2))\n",
    "# 采用梯度下降法调整权重矩阵和偏移矩阵\n",
    "# 调整的步长\n",
    "train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)\n",
    "with tf.Session() as sess:\n",
    "    # 初始化变量\n",
    "    sess.run(tf.global_variables_initializer())\n",
    "    # 训练10000次\n",
    "    for i in range(0,10000):\n",
    "        sess.run(train_step,feed_dict={x:dateNormal,y:priceNormal})\n",
    "    # 通过训练好的模型做出预测\n",
    "    predict = sess.run(layer2,feed_dict={x:dateNormal})\n",
    "    predPrice = np.zeros([15,1])\n",
    "    for i in range(0,15):\n",
    "        # 之前已经归一化过，故要乘3000\n",
    "        predPrice[i,0] = (predict*3000)[i,0]\n",
    "    plt.plot(date,predPrice,'b',lw=3)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYEAAAD8CAYAAACRkhiPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3XmYFNXZ9/HvzS4iiDJuMAoYVEQTkHELcYkrEhWXLBiDhjxCQE00LolLXpMYNcaoiQtLUAjRGHEBFI3Kg08QYxRkQBbJiAwCOoI6sisKDNzvH6c63QMzTA/TM9U9/ftcV19Wnaquunuk6+4659Q55u6IiEh+ahJ3ACIiEh8lARGRPKYkICKSx5QERETymJKAiEgeUxIQEcljSgIiInlMSUBEJI8pCYiI5LFmcQdQkw4dOnjnzp3jDkNEJGfMnj37U3cvSGffrE8CnTt3pri4OO4wRERyhpktT3dfVQeJiOQxJQERkTymJCAikseUBERE8piSgIhIHlMSEBHJY0oCIiJZ5vHH4cEHoSEmfsz65wRERPLJm2/CoEGwaRMsXAj33w/Nm9ff+XQnICKSJcrKoH//kAAApk+HL76o33MqCYiIZIGNG+G88+Cjj8L6XnvB5MnQtm39nldJQEQkZu6hCmj27LDerBk8/TR85Sv1f24lARGRmP32t/Dkk8n1Bx6Ab36zYc6tJCAiEqOnn4Zf/Sq5fuWVMHRow51fSUBEJCZvvQWXXJJcP+00+OMfGzaGGpOAmRWa2TQzKzGzhWZ2VVT+NTN7w8wWmNlzZtY25T03mlmpmS0yszNTyvtGZaVmdkP9fCQRkez30Udw7rnJ3j/duoUqoWYN3HE/nTuBCuBad+8OHAdcYWaHAw8DN7j7kcAk4HqAaNsAoAfQFxhhZk3NrCkwHDgLOBy4KNpXRCSvfPll6AlUVhbW27ULPYHat2/4WGpMAu6+0t3nRMsbgBKgI3Ao8Gq021Tgwmi5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oRuQnwGNmNp8wZekdMcdTpehu5WlgDrCA8B3KqidGzexx4A3gUDMrM7P/Ae4ETjezxYReLHfGGWOqauJ9ENgDmBp910bFGmSkmlhzmp4YFhHJY7oTEBHJY0oCIiJ5TElARCSPKQmIiOQxJQERkTymJCAikseUBERE8piSgIhIHvv/IjCiuVjdJwQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 实现人工神经网络（ANN）\n",
    "# 为了便于计算，将日期归一化\n",
    "dateNormal = np.zeros([15,1])\n",
    "priceNormal = np.zeros([15,1])\n",
    "# i从0到14\n",
    "for i in range(0,15):\n",
    "    dateNormal[i,0] = i/14.0\n",
    "    priceNormal[i,0] = endPrice[i]/3000.0\n",
    "# 输入层：N行1列 x为日期，y为价格\n",
    "x = tf.placeholder(tf.float32,[None,1])\n",
    "y = tf.placeholder(tf.float32,[None,1])\n",
    "# 隐藏层\n",
    "# w1为1*10d的随机变量矩阵，矩阵中的值介于0,1之间\n",
    "w1 = tf.Variable(tf.random_uniform([1,10],0,1))\n",
    "b1 = tf.Variable(tf.zeros([1,10]))\n",
    "wb1 = tf.matmul(x,w1)+b1\n",
    "# 激活函数\n",
    "layer1 = tf.nn.relu(wb1)\n",
    "# 输出层\n",
    "w2 = tf.Variable(tf.random_uniform([10,1],0,1))\n",
    "b2 = tf.Variable(tf.zeros([15,1]))\n",
    "wb2 = tf.matmul(layer1,w2)+b2\n",
    "layer2 = tf.nn.relu(wb2)\n",
    "# 损失函数 (y - predict)^2 即标准差\n",
    "loss = tf.reduce_mean(tf.square(y - layer2))\n",
    "# 采用梯度下降法调整权重矩阵和偏移矩阵\n",
    "# 调整的步长\n",
    "train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)\n",
    "with tf.Session() as sess:\n",
    "    # 初始化变量\n",
    "    sess.run(tf.global_variables_initializer())\n",
    "    # 训练10000次\n",
    "    for i in range(0,10000):\n",
    "        sess.run(train_step,feed_dict={x:dateNormal,y:priceNormal})\n",
    "    # 通过训练好的模型做出预测\n",
    "    predict = sess.run(layer2,feed_dict={x:dateNormal})\n",
    "    predPrice = np.zeros([15,1])\n",
    "    for i in range(0,15):\n",
    "        # 之前已经归一化过，故要乘3000\n",
    "        predPrice[i,0] = (predict*3000)[i,0]\n",
    "    plt.plot(date,predPrice,'b',lw=3)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
